<#include "/oms/iframe/common/head_index.html" />
<@dictionary type="function" fields="Status,FileType"></@dictionary>
<@dictionary type="listjson" fields="Status,FileType"></@dictionary>
<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">系统文件管理</h3>
				<div class="box-tools pull-right">
					<@shiro.hasPermission name="system:config:file:add">
						<a class="btn btn-sm btn-primary" target="modal" modal="lg" href="${request.contextPath}/system/config/file/add">添加</a>
					</@shiro.hasPermission>
				</div>
			</div>
			<div class="box-body">
				<div class="clearfix">
					<form id="search-form" class="" >
						<div class="col-md-3">
							<div class="input-group date ">
								<div class="input-group-addon">
									<i class="fa fa-calendar"></i>
								</div>
								<input type="text"  class="form-control pull-right" name="beginCreatedTime" placeholder="选择开始时间...">
							</div>
						</div>
						<div class="col-md-3">
							<div class="input-group date ">
								<div class="input-group-addon">
									<i class="fa fa-calendar"></i>
								</div>
								<input type="text" class="form-control pull-right" name="endCreatedTime" placeholder="选择结束时间...">
							</div>
						</div>
						<div class="col-md-3">
							<div class="input-group">
								<span class="input-group-addon"><i class="fa fa-search"></i></span>
								<input type="text" class="form-control" name="title" placeholder="根据文件标题搜索...">
							</div>
						</div>
						<div class="col-md-3">
							<button type="button"  class="btn btn-primary btn-grid-refresh">搜索</button>
						</div>
					</form>
				</div>
				<div class="clearfix" style="padding-top: 15px;">
					<table id="dataGrid" class="table table-bordered table-striped">

					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<#include "/oms/iframe/common/setting_index.html" />
<#include "/oms/iframe/common/bottom_index.html" />

<script type="text/javascript">
    $dataGrid = $("#dataGrid");

    /**
     * 下载
     */
    $("#down").on("click",function () {
        var obj = $dataGrid.bootstrapTable('getSelections');
        $.each(obj,function(index,item){
            window.location.href="${request.contextPath}/system/config/file/down/"+item.id;
        });

    });

	$(".btn-grid-refresh").on("click",function () {
        fileReload();
    });
	function fileReload(){
		$("#dataGrid").bootstrapTable('refresh');
	}
    $(function () {

    	$.datetimepicker.setLocale('ch');
		//初始化时间选择器
		$('[name=beginCreatedTime]').datetimepicker({
			format:"Y/m/d 00:00:00",      //格式化日期
			timepicker:true,    //开启时间选项
			yearStart:2000,     //设置最小年份
			yearEnd:2050,        //设置最大年份
			todayButton:false    //关闭选择今天按钮
		});

		//初始化时间选择器
		$('[name=endCreatedTime]').datetimepicker({
			format:"Y/m/d 23:59:59",      //格式化日期
			timepicker:true,    //开启时间选项
			yearStart:2000,     //设置最小年份
			yearEnd:2050,        //设置最大年份
			todayButton:false    //关闭选择今天按钮
		});

        initDataGrid();
    });
    function initDataGrid(){

        $dataGrid.bootstrapTable({
            idField : "id",
            columns : [[
                {title: "", field: "checkbox" ,checkbox:true},
                {
                    title: "文件标题",
					field: "title" ,
					formatter: function (value, row, index) {
                        if(row.title){
							return '<a href="'+row.urlFull+'" target="_blank">'+row.title+'</a>';
                        }else {
                            return '<a href="'+row.urlFull+'" target="_blank">'+row.urlFull+'</a>';
                        }
					}
                },
				{
					title: "图片展示",
					field: "urlFull" ,
					formatter: function (value, row, index) {
						if(row.type===1){
							return '<img style="max-width:200px;" src="'+row.urlFull+'" alt="'+row.urlFull+'">';
						}else {
							return '';
						}
					}
				},
                {title: "文件类型", field: "type" ,formatter : getFileTypeDictName},
                {title: "文件大小", field: "size" ,formatter:function (value, row, index) {
					return row.size +" K";
                }},
                {title: "创建人", field: "createdBy"},
                {title: "创建时间", field: "createdTime", sortable: true,formatter:dateFormat},
                {title: "状态", field: "status",formatter : getStatusDictName},
                {title: "操作", field: "operate", align: 'center',formatter: operateFormatter}
            ]],
            url : '/system/config/file/grid',
            queryParams: function(files){
            	var searchForm = $("#search-form");
				var formData = searchForm.serializeObject();
				if(files.sort){
					formData["sort"]=files.sort;
					formData["order"]=files.order;
				}
				formData["offset"]=files.offset;
				formData["limit"]=files.limit;

                return formData;
            },
            responseHandler : function (res) {
                return {
                    rows : res.rows,
                    total : res.total
                }
            },
            search : false,
            searchOnEnterKey : false,
            sortName : 'createdTime',
            sortOrder : 'asc',
            pagination : true,
            sidePagination : 'server',
            pageSize: 10,
            pageList : [10,20, 40, 50, 100],
            showRefresh : true,
            showToggle : true
        });
    }

    function operateFormatter(value, row, index) {
        return [
            '<a class="btn btn-sm btn-info "  title="查看" target="modal" modal="lg" href="${request.contextPath}/system/config/file/view?id='+ row.id + '"  >',
            '	<i class="glyphicon glyphicon-check"></i> ',
            '</a>  ',
            '<a class="btn btn-sm btn-warning" title="修改" target="modal" modal="lg" href="${request.contextPath}/system/config/file/update?id='+ row.id + '" >',
            '	<i class="glyphicon glyphicon-edit"></i> ',
            '</a>  ',
            '<a class="btn btn-sm btn-danger"  title="删除" callback="fileReload()" data-body="确认要删除吗？" target="ajaxTodo" method="DELETE" href="${request.contextPath}/system/config/file/delete?id='+ row.id + '">'
			+'	<i class="glyphicon glyphicon-remove"></i>'
            + '</a>&nbsp;'
        ].join('');
    }
</script>